import Vue from 'vue'
import VueRouter from 'vue-router'

// 赋能中心首页
const CenterHome = () => import('../views/centerHome/Home.vue')
const CenterDetails = () => import('../views/centerHome/CenterDetails.vue')
const CenterIntroduce = () => import('../views/centerHome/CenterIntroduce.vue')
const ExpertIntro = () => import('../views/centerHome/ExpertIntro.vue')
const LeaderCare = () => import('../views/centerHome/LeaderCare.vue')
const LeaderCareInfo = () => import('../views/centerHome/LeaderCareInfo.vue')
const ExpertDetailMobel = () => import('../views/centerHome/ExpertDetailMobel.vue')
// 行情资讯
const QuoteHome = () => import('../views/quoteHome/Home.vue')
const InformationsNews = () => import('../views/quoteHome/InformationsNews.vue')
const ExpertArticles = () => import('../views/quoteHome/ExpertArticles.vue')
const SharingData = () => import('../views/quoteHome/SharingData')
const CustormerCase = () => import('../views/quoteHome/CustomerCase.vue')
const QuoteInfomation = () => import('../views/quoteHome/QuoteInfomation.vue')
// 个人中心
// 企业用户  
const SelfHome = () => import('../views/self/Home.vue')
const CompIndex = () => import('../views/self/company/index.vue')
const CompReqDetail = () => import('../views/self/company/reqDetail.vue')
const AddDemandMobile = () => import('../views/self/company/addDemandMobile.vue')
const CompReqDetailMobile = () => import('../views/self/company/reqDetailMobile.vue')
const ProjectAssessMobel = () => import('../views/self/company/projectAcssess.vue')
// 管理用户
const ManUser = () => import('../views/self/manage/users.vue')
const ManReqAll = () => import('../views/self/manage/reqAll.vue')
const ManReqDetail = () => import('../views/self/manage/reqDetail.vue')
const AddManage = () => import('../views/self/manage/addManage.vue')
const ProjectAll = () =>import('../views/self/manage/projectAll.vue')
// 手机端展示
const UserDetailInfoMobel = () => import('../views/self/manage/userDetailInfoMobel.vue')
const CompanyAssess = () => import('../views/self/manage/companyAssessMobel.vue')
const AssessSelf = () => import('../views/self/manage/assessSelfMobel.vue')
const ReqDetailMobel = () => import('../views/self/manage/reqDetailMobel.vue')
const PersonAssignMobel = () => import('../views/self/manage/PersonAssignMobel.vue')
const CreateProjectMobel = () => import('../views/self/manage/createProjectMobel.vue')
const UserAdminMobel =() =>import('../views/self/manage/userAdminMobel.vue')
const ProjectDetailMobel =() =>import('../views/self/manage/projectDetail.vue')
// 个人顾问用户
const AdvIndex = () => import('../views/self/adviser/index.vue')
const AdvDetail = () => import('../views/self/adviser/adviserDetail.vue')
const advSelfAssessment = () => import('../views/self/adviser/selfAssessment.vue')
// 合作伙伴
const PartIndex = () => import('../views/self/partner/index.vue')
const PartDetail = () => import('../views/self/partner/partnerDetail.vue')
const PartAdduser = () => import('../views/self/partner/adduser.vue')
const SelfAssessment = () => import('../views/self/partner/selfAssessment.vue')
// 赋能中心首页下的六个版块
const LogisticsNetwork = () => import('../views/centerHome/LogisticsNetwork.vue')
const AssetNetwork = () => import('../views/centerHome/AssetNetwork.vue')
const BoardRoom = () => import('../views/centerHome/BoardRoom.vue')
const SmartEnterprise = () => import('../views/centerHome/SmartEnterprise.vue')
const IndustryIntelligent = () => import('../views/centerHome/IndustryIntelligent.vue')
const InnovationInteraction = () => import('../views/centerHome/InnovationInteraction.vue')

Vue.use(VueRouter)
//获取原型对象上的push函数
const originalPush = VueRouter.prototype.push
//修改原型对象中的push方法
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}
const routes = [{
  path: '/',
  redirect: '/centerHome'
}, {
  path: '/centerHome',
  component: CenterHome,
  redirect: "/centerHome/centerIntroduce",
  children: [{
    path: 'centerDetails',
    component: CenterDetails
  }, {
    path: 'centerIntroduce',
    component: CenterIntroduce
  }, {
    path: 'expertIntro',
    component: ExpertIntro
  }, {
    path: 'leaderCare',
    component: LeaderCare
  }, {
    path: 'leaderCareInfo',
    component: LeaderCareInfo
  }, {
    path: 'expertDetailMobel',
    component: ExpertDetailMobel
  }, , {
    path: 'logisticsNetwork',
    component: LogisticsNetwork
  }, , {
    path: 'assetNetwork',
    component: AssetNetwork
  }, , {
    path: 'boardRoom',
    component: BoardRoom
  }, , {
    path: 'smartEnterprise',
    component: SmartEnterprise
  }, , {
    path: 'industryIntelligent',
    component: IndustryIntelligent
  }, , {
    path: 'innovationInteraction',
    component: InnovationInteraction
  }, ]
}, {
  path: "/quoteHome",
  component: QuoteHome,
  redirect: '/quoteHome/quoteInfomation',
  children: [{
    path: '/',
    component: QuoteInfomation
  }, {
    path: 'quoteInfomation',
    component: QuoteInfomation
  }, {
    path: 'informationsNews',
    component: InformationsNews
  }, {
    path: 'expertArticles',
    component: ExpertArticles
  }, {
    path: 'sharingData',
    component: SharingData
  }, {
    path: 'custormerCase',
    component: CustormerCase
  }]
}, {
  path: '/self',
  component: SelfHome,
  children: [{
      path: 'company/compIndex',
      component: CompIndex
    }, {
      path: 'company/compReqDetail',
      component: CompReqDetail
    }, {
      path: "company/addMemandMobile",
      component: AddDemandMobile
    }, {
      path: 'company/compReqDetailMobile',
      component: CompReqDetailMobile
    }, {
      path: 'company/projectAssessMobel',
      component: ProjectAssessMobel
    },
    {
      path: 'manage/manUser',
      component: ManUser
    }, {
      path: 'manage/manReqAll',
      component: ManReqAll
    }, {
      path: 'manage/manReqDetail',
      component: ManReqDetail
    }, {
      path: 'manage/addManage',
      component: AddManage
    }, {
      path: 'manage/userDetailInfoMobel',
      component: UserDetailInfoMobel
    }, {
      path: 'manage/companyAssess',
      component: CompanyAssess
    }, {
      path: 'manage/assessSelf',
      component: AssessSelf
    }, {
      path: 'manage/reqDetailMobel',
      component: ReqDetailMobel
    }, {
      path: 'manage/personAssignMobel',
      component: PersonAssignMobel
    }, {
      path: "manage/createProjectMobel",
      component: CreateProjectMobel
    }, {
      path: 'manage/projectAssessMobel',
      component: ProjectAssessMobel
    },{
      path: 'manage/projectAll',
      component: ProjectAll
    },
    {
      path: 'manage/projectDetail',
      component: ProjectDetailMobel
    },
    {
      path: 'manage/userAdminInfoMobel',
      component:UserAdminMobel
    },
     {
      path: "adviser/advIndex",
      component: AdvIndex,
    }, {
      path: "adviser/advDetail",
      component: AdvDetail
    }, {
      path: "adviser/advSelfAssessment",
      component: advSelfAssessment
    }, {
      path: "partner/partIndex",
      component: PartIndex
    }, {
      path: "parnter/partDetail",
      component: PartDetail
    },
    {
      path: "parnter/partAdduser",
      component: PartAdduser
    }, {
      path: "parnter/selfAssessment",
      component: SelfAssessment
    }
  ]
}]


const router = new VueRouter({
  routes
})

// 在这里判断2级路由，判断用户权限
router.beforeEach((to, from, next) => {
  const userType = sessionStorage.getItem('userType')
  console.log(userType)
  if (to.path === '/self/adviser/advIndex') {
    if (userType == 12) {
      next()
    } else {
      next({
        path: '/'
      })
    }
  } else if (to.path === '/self/company/compIndex') {
    if (userType == 11) {
      next()
    } else {
      next({
        path: '/',
      })
    }
  } else if (to.path === '/self/partner/partIndex') {
    if (userType == 10) {
      next()
    } else {
      next({
        path: '/'
      })
    }
  } else if (to.path === '/self/manage/manUser') {
    if (userType == 9 || userType == 13) {
      next()
    } else {
      next({
        path: '/'
      })
    }
  } else {
    next();
  }
})



export default router